// 引入pinia
import { defineStore } from "pinia";
// 定义 store 并导出
export const useUserStore = defineStore("user", {
  // 定义状态数据
  state: () => ({
    userId: undefined,
    username: undefined,
  }),

  // 获取数据的方法
  getters: {
    Number: (state) => state.userId,
    String: (state) => state.username,
  },

  // 修改数据方法
  actions: {
    setUserInfo(id, name) {
      this.userId = id;
      this.username = name;
    },
  },

  // 使用持久化
  persist: {
    enabled: true,
    storage: localStorage,
    key: "userInfo",
    path: undefined,
  },
});
